package cn.gson.crmdemo.model.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONArray;

import cn.gson.crmdemo.model.dao.HkjlDao;
import cn.gson.crmdemo.model.mapper.FkjlMapper;
import cn.gson.crmdemo.model.mapper.HkjlMapper;
import cn.gson.crmdemo.model.pojo.Getmoneyplan;
import cn.gson.crmdemo.model.pojo.Getmoneyrecord;
import cn.gson.crmdemo.model.pojo.Invoice;
import cn.gson.crmdemo.model.pojo.Order;
import cn.gson.crmdemo.model.pojo.Returne;
import cn.gson.crmdemo.model.vo.HkjlVo;


@Service
@Transactional(rollbackFor=Exception.class)
public class HkjlService {
	@Autowired
	HkjlDao kd;
	@Autowired
	HkjlMapper km;
	@Autowired
	FkjlMapper fm;
	//查询回款记录
	public JSONArray hkjl(String getmoneyDate,Integer payType,Integer fpZt){
		return km.selecthkjl(getmoneyDate,payType,fpZt);
		
	}
	//查询回款计划
	public JSONArray selectjh() {
		return km.selectjh();
		
	}
	//添加回款记录
	public void tjhkjl(HkjlVo hkjl){
		Getmoneyplan gl=new Getmoneyplan();
		gl.setGetplanId(hkjl.getGetplanId());
		Order or=new Order();
		or.setOId(hkjl.getOrderId());
		Getmoneyrecord gd =new Getmoneyrecord();
		gd.setOrder(or);
		gd.setGetmoneyplan(gl);
		gd.setGetEmpName(hkjl.getGetEmpName());
		gd.setGetmoneyDate(hkjl.getGetmoneyDate());
		gd.setGetForeignRemark(hkjl.getGetForeignRemark());
		gd.setGetmoneyGetMoney(hkjl.getGetmoneyGetMoney());
		gd.setPayType(hkjl.getPayType());
		gd.setFpZt(0);
		kd.save(gd);
	}
	//修改
	public void xghkjl(HkjlVo hkjl){
		Getmoneyrecord gd =new Getmoneyrecord();
		gd=kd.findById(hkjl.getGetmoneyId()).get();
		gd.setGetEmpName(hkjl.getGetEmpName());
		
		
		gd.setPayType(hkjl.getPayType());
		kd.save(gd);
	}
	/*
	 * 修改状态
	 */
	public void xgfpzt(int c,int b) {
		Getmoneyrecord gd=kd.findById(c).get();
		gd.setFpZt(b);
		kd.save(gd);
		
	}
	//日期模糊查询
	public JSONArray selectmh(String rq){
		return km.selecsj(rq);
	}
	//付款方式
	public JSONArray selectfs(Integer a) {
		return km.selectfs(a);
	}
	//是否开票
	public JSONArray selectfp(Integer b) {
		return km.selectfp(b);
	}
}
